package com.roy.springboot.security.oauth2.controller;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.security.Principal;

/**
 * 区别 hasRole 和hasAuthority 示例
 * Created by elloxxn on 12/14/2017.
 */
@RestController
public class HomeController {

    @GetMapping(value = "/")
    public String home() {
        return "Hello world";
    }

    @GetMapping(value = "/private")
    public String privateArea() {
        return "Private area";
    }

    @GetMapping(value = "/s-role1")
    @PreAuthorize("hasAuthority('ROLE_ANON')")
    public Principal getSome1(Principal principal) {
        System.out.println("role1..........111");
        return principal;
    }
    @GetMapping(value = "/s-role2")
    @PreAuthorize("hasAnyRole('ACTUATOR','USER')")
    public Principal getSome2(Principal principal) {
        System.out.println("role2..........222");
        return principal;
    }
}
